﻿Public Class frmMechanicAED
    Public Sub LoadSex()
        cboSex.ValueMember = "sex_id"
        cboSex.DisplayMember = "sex"
        cboSex.DataSource = Cmd.ExecuteDataTable("select * from tblSex where Active = 1")
    End Sub
    Public Sub LoadProvince()
        cboProvince.ValueMember = "Pro_id"
        cboProvince.DisplayMember = "Pro_name"
        cboProvince.DataSource = Cmd.ExecuteDataTable("select * from tblProvice where Active = 1")
    End Sub
    Private Sub frmMechanicAED_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Me.StartPosition = FormStartPosition.CenterScreen
        LoadSex()
        LoadProvince()
    End Sub

    Private Sub btnClose_Click(sender As Object, e As EventArgs) Handles btnClose.Click
        Me.DialogResult = Windows.Forms.DialogResult.Cancel
    End Sub
    Private Sub Parameter()
        Cmd.Parameters("@Mechanic_code") = txtMechanicCode.Text
        Cmd.Parameters("@Mechanic_name") = txtMechanicName.Text
        Cmd.Parameters("@Sex_id") = cboSex.SelectedValue
        Cmd.Parameters("@phone") = txtTel.Text
        Cmd.Parameters("@email") = txtEmail.Text
        Cmd.Parameters("@Provice_Id") = cboProvince.SelectedValue
        Cmd.Parameters("@isaddress") = txtAdr.Text
    End Sub
    Private Sub btnEdite_Click(sender As Object, e As EventArgs) Handles btnEdite.Click
        If btnEdite.Text = "កែប្រែ" Then
            Cmd.Parameters("@Mechanic_id") = txtId.Text
            Parameter()
            Cmd.ExecuteNonQuery("UPDATE tblMechanic SET Mechanic_code = @Mechanic_code, Mechanic_name = @Mechanic_name, Sex_id = @Sex_id , phone = @phone,email = @email, Provice_Id = @Provice_Id,isaddress = @isaddress WHERE Mechanic_id=@Mechanic_id")
            frmMechanicViewer.LoadData()
            MsgBox("Updated..!")
            Me.Close()
        Else
            Parameter()
            Cmd.ExecuteNonQuery("INSERT INTO tblMechanic VALUES (@Mechanic_code, @Mechanic_name, @Sex_id , @phone,@email, @Provice_Id,@isaddress,1 )")
            frmMechanicViewer.LoadData()
            MsgBox("Save Success...!")
            Me.Close()
        End If
    End Sub
End Class